Replacing event hack with proper dependency injection