Change purging to use prepared statements