Refactoring prediction code