Added some minor error handling