Implemented clam_fopen, moved ref-count to in front of ptr