PARTIAL: Started fleshing out query/scan. Needs testing.