Move flag-related code into new pkg package

reasonable.