better algorithm, still getting there
recursive is better but group number is still off