Added preliminary error checking