Cleanup building of sql