refactoring serverside code