bug with replacing elements - wrong elems in arrys