Bug fixes in a poorly coded portion of the algorithm