place signals handling function before while