Some more code and minor reshuffle