Further cleanup of VarReplacer's replace() function
Refactoring varreplacer's replace() method by using 2 helper functions
Improving comments
Better function names and improve comments