Fixed memory leaks
Server refactoring