Speed and memory improvements

* Changed array to be continuous, so no more layer splitting