added dtor and error checking