corrections, added error checking
updated changes