General improvements + code reorganization