Fixed logic with index handling when changin values