Arrays values change not working properly