Changed `map` to `map!` at various places to avoid extra array creation.

Changed `map` to `map!` at various places to avoid extra array creation.