Fixed reference counting, IS_REFERENCE and IS_INDIRECT support