this logic repeats like 4 times, maybe refactor it?