refactor and fix some mistake