Bug fixes, typos, and cleanup