Misc bug fixing and cleanup for 13.1 factory.

Please review and for details please see each commit descriptions,