refactoring making flags string

refactoring making flags string to add flags easily.

and if flags == 0, it doesn't need to add ","