added some comments to the main mehtod that explain the overall approach