Move caching of requirements to helper function and add unit tests.