Minor performance optimisations.
Fixed line endings.
Fixed ref-counting.