Use reduce instead of apply.