bug in ref occurence count solved + trying to address memory issues but failed