Fixed #18 Server hangs on 2nd or subsequent requests + some refactoring