Added better logging and exception formatting for errors.