re-structuring the main function - adding option handler