Minor bug fixes

I noticed a few issues with the script when trying to use it, and thought you might want to merge them back in