Reorganize some code
Fix typo