[bugfixes] added error checks and exception handling