cleaned up main.c and mainloop.c