fixed a ref counting bug