refactored and first tests added