Changed purging function, added master ref updating