Updated to error checking