improved exception handling in bind_context