some improvements, still not perfect