server refactoring: event dispatcher moved to function