set signal handlers at more appropriate places