Added code needed for some tests (SJTU assignment).