Use capture list to remove duplicate code