Fix some typos.
Refactor to reduce complexity.
Merge pull request #137 from cenouro/refactor

Refactor