improving sql extraction