refactor the last patch;r=stas