Port code from Nuophoto