JCL,

I updated the top post with the entirety of the function which includes the upper and lower bound calculations.