Refactor three_of_a_kind