debugging logging tuning and tidyig up