Minor fixes

I have fixed an error, and improved the script a bit. Otherwise it looked good.