Minor reorg of code