Bug and typo fixes