splits functions to separate view logic and fixes templates to work with new functions