changed flag handling and added M-flag