Reorganized a bit to help coverity scan.