code clean up and log improovements