refactor: Move to a visitor pattern for recording events rather than inspecting and casting objects.