fix a bug and improve the code