initial refactor #2
encapsulated server class
separated functionality into some member functions in client