Changed console detecting, added more debug code