Factored out common constructor code.