add test, fix found bugs