Better protocol logic, added server automat