Nonparametric Covariance Function Estimation for Functional and Longitudinal Data