reapplied fixes to patch branch