fix NA detection. TODO: refactor out to function