refactored code to separate files for controller and view