To make this more extensible, I think it might help to split each of these components out into its own method.