Add processing of server ack messages and some code refactoring.