Refactor and move codes