bug fix, some improvements