refactor bug fixs