Nearly finished pearls stuff, still generating sql