server side code refactoring