flags and value calculation