Beginning of output tv code - it is spaghetti code...