code cleanup and reorg by cherwin