Refactor better logging