refactor out some code from .calculate