main loop needs to be tested, almost fleshed out