refactor flash messages