Refactored some and implemented some flash messages