new functions from stacey archfield, adjusted to work with package