Fix bug and failed test