Refactoring events system and connection class.