fix bug in 82bb5ba4c8; also add test case