complete refactor - speeds are 1,500% (15 times) faster and memory usage is reduced by about 2/3 (from 25% to 9.5%)