refactored setting flash messages