Added more safeguards for activity log errors.
Fixed code style.