major refactoring & multi-threaded server