Make minefield allocation at top level, some refactoring of global variables access
Fix bug with flag