Added state prediction code