Refactoring encodings and logging