Added additional tests and refactor some server code