Some improvements to the script.

This is how I would write it.