removing repetitive code chunks