skeleton of the initialization and main LOOP