Fixed a small issue with the code and added some more cout statements
incase an error occurs