Some code reorganizing