refactored camera code