Adds main loop functionality