Added a second version that uses immutable collections