Update

Update query and fix bugs