Fix double path replacement for nested query
Fix for nested queries & test refactoring
- Bugfix (a non-breaking change that solves an issue).
- Common code
- Added Unit Tests, wherever applicable.
- Existing Tests pass
- Verified functionality locally
- Self Reviewed my code for formatting and complex business logic.