Refactored logging a bit.