Added more tests.
Small bits of code refactoring.