Replace duplicated code with helpers