refactor and remove some useless code