changed apple generation logic