Ported from latest RainbowBB