Move signal handling into functions