refactor bug fixes