add purge context and apply some cleanup