Added some error checking to existing functions.