Bug fixes to pass most tests(Except last test) in the test file.