lots of changes, new flagging mode and many bugfixes