Adding error checking and more helpful error messages

Hi