Refactored command token substitution, added tests