Moved commandline parsing into a separate function.