Updated some code to handle exceptions better

And synchronized the code with the corresponding README files