fix a bug and unused function