recycled some duplicated code