This function is copied in a bunch of places. Please move into a helper and avoid things like this in future.