rewriting the repetitive code