Improved formatting.
Improved formatting and avoided throwing hundreds of errors when 'selected' is null.
Selection#getSelectedElement should not modify ranges.