bug fixes and typo fixes