added error and exception handling