added  error checking