Tests added with some refactorings