Added error checking, usage and printing out to a file.