Refactor codes