Reorg some code and add a test