refactored server

Refacotred and working