fixed error in gapply