Added some error handling
Better error handling