Added a little more error handling