Added ref structure post processing and memory freeing calls