Fix update query to ensure that order is correct