More detailed main loop, needs lots of improvements