moved duplicate code to generic helper