Tests refactored and corrected implementation according to the corrected tests