Final Commit. Logic not tested for uncommon cases