added some check for particular cases
added new function writeCube2