Split Mainloop timer into setupMainloop and endMainloop