Restructure, refactor a little, and add unit tests

Read my commits one by one to see the changes made step by step.

Learn more about [Jasmine](http://jasmine.github.io/1.3/introduction.html).