Add logging for exceptions
Make the code more readable