Refactor flash message generation.