Added some rebalancing code to TailRec