Fix several bugs in update queries