refactor and modified bug