cleaned up main method