More code deduplication. Also normalized some line endings.