refactor codes.