refactored logic out of image view