this code is duplicated in lines 15-19, why not make a function that can be used for both?