refactored and updated tests