Fixed a couple ref counting bugs