Use ftw.profilehook instead of setuphandlers.

Same as #492 but rebased for our feature branch.