Added error handling for executing perl files. A bit of cleanup as well.