fix a bug; better test code