added error handling in sysread