Code refactoring + variable substitutions