Fixes tests. Abstracts raw query