Tried to optimize by employing collection.Counter, but it didn't
optimize at all. Special thanks to Denis Garcia