several bug fixes and style changes