Add error checking and error messages