Massive text refactoring and fixes