update main func, pass most test cases