multiple bug fixes and typo repairs