refactor, and fix bug.