removing duplicated code