Almost done with code modification. Final debugg tomorrow.
Added some test cases back. Two known bugs need to be fixed.