Borrowed main program infrastructure from Sprocket.