bug fixes and minor style improvements