Added some command line flags, removed the env var and general tidy up.