Removed loop and instead use apply