cleaned up duplicate logic
added flash messages