It seems like we should be able to make this into a map/flatMap and to make val assign into an immutable data structure. Is there a reason it needs to be mutable?

Also, I'd prefer to change the name of the val assign to something different, as I feel that assign hash collides...