tests pass, needs refractoring