fix a small bug and minor improvements