much more efficient toArray implementation
Improved implementation of set and update

Faster and cleaner