Removing duplicated code