Fixes to UB