Refactor flash message generation