Log refactor + tests