fix an issue and refactor