refactored server to increase speed