Added error messages using flash in the right places