rewritten the method and tests after watching solution video