Fixes made for 3.x ported to 4.x