Make a function for these lines of code since they are repeated elsewhere?