These two methods look similar but if you take a close look, it's different inside the `each' loop. Hence I don't think reusing `which' function is feasible.