Added more tests. Refactoring of code.