Changed `collect_by_type` to collect arrays into hashes instead of lists to make it easier to work with them.