added if conditions for writeCube function