rewrote make_safe_callback with cool trick of Prof Dr. Falcou.
better implementation of make_safe_callback