minor bug fixes, error checking, and comments