Merged changes from master to fix problems with HA not
switching over correctly. TRQ-2265