Added some more error handling and output