Refactoring and cleanup

- Updated Query implementation.
- Updated program variable-related wrappers.
- Work-in-progress, won't compile.