fixing bugs, some improvements