Get rid of duplicate code