Masktool

update to fix a number of bugs in masktool including writing out the xml file twice