Add a little more error checking

The script is slightly more verbose now, and the functions now check for
the proper number of arguments.