code review tidy and fix errors