Refactor and optimize; try out row-first for cache locality
Tweaks.