Extracting most code into three methods.