Precalculated subsets gave some speed-up.