trivial code refactoring

added a minor amount of additional sanity checking