Implemented variable substitution properly