Refactoring to support reverse variable matching for issue #2