refactor logic and view code to separate files