Added some memory optimizations from stratosk