Switched error handling to use flash()