porting from FAEA (thx Dr-Shadow)