Added additional error checking