refactoring code to better separate UI and logic, adding event handler for client updates on server