Another set of improvements and code reorganization