merge duplicated codes into one function