Added mainloop and fn handler.