fixed initial function that damaged the array and made it return a clone