refactoring server-side code