Wrap the main loop