add error log and fixed some bugs