Fixing flag conversions and it's unittests