Updated to use query as input instead of other way around.
Derp