handle signal functions inside mainloop