bug refactor