Moved code into main function.
Added default values for optional arguments.
You can get a diff of changes.
Reduced duplication of code.
Used writelines into stdout stream instead of 'for' loop
Fixed indentation bug. Removed extra argument from call of tagArgDescr function.