Apply doesn't work when using repeat function