Added new tests, minor refactorings.