simplified popvar and added na.rm argument