Moving the main loop to a class method