reorganised code to make use of logger