fix bug, and clean code