added error checkking