split the update, insert and deelte into three functions