Rewrite of PRI progress and message handling. Fixes bugs #5266 and #4468