design algorithm for update; rewrite algorithms for other insert, delete and query