I sprinted to get this algorithm correctly implemented in a week. While it is correct, the garden needs some tending.