add error checking (esp. NAs) and revise documentation