Fixed some silly bugs, added tests, reach 100% coverage.