weighted and unweighted prediction optimisation, removal of duplicate code