Adds a couple tests. Refactors some code.