Correcting the update method in Segment Tree