added error messages and try catch