fix bug and refactor flash message