Some code reorganization