Optimized alg but need to fix stale getRight|Left functions