Added bunch of functions, fixed substitution