Seems like this whole block should go in it's own module.