Added logging for errors with try/catch