started fixing the loop from end of arra to beginning