bug fixes and minor improvements