some fix and refactor