This stuff seems like it's repeated verbatim like 4 times. Might want to consider writing a helper function.