Added additional error checking for better trouble shooting