code refactor bug