Update code to fix issues #2387