Refactor server side code to break out helper methods