logic fixes and typo corrections