Add support for commandline arguments and better error handling.