made functions from duplicate code