Added some error control.