refactored display of flash messages