Some refactoring

Also some rebalance