Bugfixes

Cleanup bugfix.
Flags bugfix