fix some terrible scoping issues

causing “Uncaught TypeError: Cannot read property 'photos' of undefined
“ and other errors.