Refactored and updated tests