refactored server. Made it more modular and asynchronous