fixed header length calculation
added additional server events
minor code refactoring