fix bug, improve code