a seperate function for this stuff

this makes this function reusable