added error  handling