added error handlers to all functions