Make sure XMLDocument is deleted; Code clean up; Add test;