These copy pasted functions should go into a util file instead so they can be used in both places.