Move duplicate code to own method

Change-Id: I8f9dfb461b9bfc2071d372b8010bf86899c23a24
Merge "Move duplicate code to own method"