split function to reduce cyclomatic complexity (per rubocop)

Change-Id: I0e88284c6374298328f0ac40bad23113812201b1