Fixed a bug whereby a, b, c, and d values were not getting re-set after hitting a boundary.
Removed some debugging print statements.
Eliminated duplicate code.