made parsing of arguments more comprehensive and did code cleaning by creating functions to avoid redundant code