Refactored and new tests added