Adding in some error checking in utility functions.