refactored server side code