Added command line option for filename
Cleaned up loop so it doesn't use a separate string for output