ported additional patches from LD31