Restructure code and pass all test.