get rid of duplicate code