more efficient withForeignArray
tidy imports