Minor fixes

I have fixed an error, and improved the script a bit.