added error checking for system calls