after major refactoring the server seems to work. Still need more testing.