Some code reorganization/cleanup