this part of code is duplicated many times, create private method for this.