Output file's file name fix etc

Fixed file name problem for output files from curl commands.
Cleaned up code formatting.
Added more documentation and clarity to script.