clean code, better logging, small optimisation