XE compatibility and some cleanup