Fixed singleItem()

Changed it to use a map instead of 2 nested loops.