some reorg and refactering