Fixed last example by using apply