refactor almost end