refactor all codes