fix several bugs & some improvements