fixed some bugs, added error-handler