Added support for command line arguments

Cleaned up code a little bit as well, and added copyright notice.