changed main loop to work without SDL and use timed wait