Refactors, fixes

Re-visit the log collection, get rid of some code duplication, and fixed some issues. Refer to the individual commits for more details.