Created main loop and lot of other functions.