Fixed a typo and refactored some code.