Reference Count Fix

Fixed Reference counting in a number of places.