added connection handling and basic event system