some bug fixes and minor modifications