Patches from Evgeny (@eltjpm)