move handler building into one function