added comments to the main method that explain the overall approach