replace j with newLength