Improving speed and decreasing memory usage, work in progress