code tidy and refactor