Added some tests + refactoring.