added basic main loop function