reworked flags ; fixing lots of bugs