This is a lot of duplication, factor it out?