added error handling using flash