Put the arguments parser in a separate function.
Random fix and moved some stuff to functions.
Moved command unfolding to a function. Still lot of work to be done there.
Added check for invalid arguments.