Added utils for errors, fixed some bugs.