repeated code. make it a function