refactored server side