Move argument parsing code to the ifmain block
Update for new usage