Some more refactoring and cleanup after code inspection