Code cleanup and typo fixes