Revert "Revert "Cumulative fixes for #2542 #2544""

This reverts commit d4c9121ad07d859e569b8591aa17852c202061e1.