Fix bug and improve the test method