Some refactorings for better logging and cleaner? (haha) code