Consider splitting this into a helper function