remove intermediate array and use the CanBuildFrom instance directly