Fix a bug and enhance test