Split EventQ main into functions and main