refactor code: combine three lines into one member func