moved signal handlers to clean up code