Modified template delete script to also remove entries from PAGES table