a bug fix and minor improvements.