Adding some more error handling