More refactor and improved command line arguments