small bug corrections and some improvements