refactor the src and fix a bug