Improved flag-handling.