Fixed signal handler, also checks to make sure file is open before closing
blocks all signals until handler is setup