modified the heck out of the file
functionized things
added some better error handling/reporting

fixed a missing '/' and removed some useless comments

removed an extra escapeshellarg call