got rid of duplicate code