Merge with useful changes from XP version