Now with sql generation, improved tests