Refactoring server-side code