refactor and code tidy