completed server logic and cleaned up code.