refactoring prediction code

merging common stuff