Trying to remove duplicated code