Code refactor.

Moving out of material evaluation to its own function.