Made small refactoring and added new tests