refactored and more unit tests