Added moved some client functionality into a callback to play nice with glib event loops.