refractored code for flash messages and styled them