add test, and fix bug