Fixed bug in flag handling