Improvement: greatly simplified command line arguments processing
De-duplicated code
Code changes suggested by scrutinizer-ci.com