Added some error handles.