Cleaner version of bug-fix for 528, also moved substitutions.h out of theory.h
for faster compilation