Devices having a p-i-n structure