Added console output safety and preventing infinite looping in openning
and closing console.