get rid of some repeated code