got rid of repetitive code