--- a/nouveau-pm/monitor_downclocking.c
+++ b/nouveau-pm/monitor_downclocking.c
@@ -22,14 +22,12 @@
  */
 
 #include <stdio.h>
-#include <string.h>
-#include <sys/time.h>
+
 #include <X11/Xlib.h>
 
 #include "NVCtrl.h"
 #include "NVCtrlLib.h"
 
-#define	NOUVEAU_TIME_WAIT 180
 
 inline void
 read_card_specific_registers(void)
@@ -44,7 +42,7 @@
 	static int fanspeed;
 	if (read_fanspeed != fanspeed) {
 		read_fanspeed = fanspeed;
-		fprintf(stderr, info);
+		fprintf(info);
 	}
 #endif
 }
@@ -53,30 +51,26 @@
 read_bus_rate(Display *dpy)
 {
 	static int bus_rate;
-
+	
 	XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
                                          0, NV_CTRL_BUS_RATE, &bus_rate);
-	fprintf(stderr, "NV_CTRL_BUS_RATE = %d\n", bus_rate);
-}
-inline void
-check_bus_type(Display *dpy)
+	fprintf(stderr, "NV_CTRL_BUS_RATE = %d\n", bus_rate);      
+}
+void check_bus_type(Display *dpy)
 {
 	static int bus_type;
-	char tmp[100];
-
+	
 	XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
                                          0, NV_CTRL_BUS_TYPE, &bus_type);
-//	fprintf(stderr, "NV_CTRL_BUS_TYPE = %d\n", bus_type);
-	strcpy(tmp, "NV_CTRL_BUS_TYPE = ");
+//	fprintf(stderr, "NV_CTRL_BUS_TYPE = %d\n", bus_type);      
+	fprintf(stderr, "NV_CTRL_BUS_TYPE = ");
 	switch(bus_type)
 	{
-		case NV_CTRL_BUS_TYPE_AGP: strcat(tmp, "AGP"); break;
-		case NV_CTRL_BUS_TYPE_PCI: strcat(tmp, "PCI"); break;
-		case NV_CTRL_BUS_TYPE_PCI_EXPRESS: strcat(tmp, "PCI-Express"); break;
-		case NV_CTRL_BUS_TYPE_INTEGRATED: strcat(tmp, "Integrated"); break;
-		default: strcat(tmp, "unknown");
-	}
-	fprintf(stderr, "%s\n", tmp);
+		case NV_CTRL_BUS_TYPE_AGP: fprintf(stderr, "AGP\n"); break;
+		case NV_CTRL_BUS_TYPE_PCI: fprintf(stderr, "PCI\n"); break;
+		case NV_CTRL_BUS_TYPE_PCI_EXPRESS: fprintf(stderr, "PCI-Express\n"); break;
+		case NV_CTRL_BUS_TYPE_INTEGRATED: fprintf(stderr, "Integrated\n"); break;
+	}
 
 	read_bus_rate(dpy);
 }
@@ -86,146 +80,132 @@
 
 	ret = XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_GPU, 0,
 										 0, NV_CTRL_GPU_CORE_TEMPERATURE, &i);
-	fprintf(stderr, "%sNV_CTRL_GPU_CORE_TEMPERATURE = %d\n", ret ? "" : "Failed ", i);
+	fprintf( stderr, "%sNV_CTRL_GPU_CORE_TEMPERATURE = %d\n", ret ? "" : "Failed ", i);
 
 	/* ------------------------------------------------------------------------------*/
 	ret = XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_GPU, 0,
 										 0, NV_CTRL_GPU_CORE_THRESHOLD, &i);
-	fprintf(stderr, "%sNV_CTRL_GPU_CORE_THRESHOLD = %d\n", ret ? "" : "Failed ", i);
+	fprintf( stderr, "%sNV_CTRL_GPU_CORE_THRESHOLD = %d\n", ret ? "" : "Failed ", i);
 
 	ret = XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_GPU, 0,
 										 0, NV_CTRL_GPU_DEFAULT_CORE_THRESHOLD, &i);
-	fprintf(stderr, "%sNV_CTRL_GPU_DEFAULT_CORE_THRESHOLD = %d\n", ret ? "" : "Failed ", i);
+	fprintf( stderr, "%sNV_CTRL_GPU_DEFAULT_CORE_THRESHOLD = %d\n", ret ? "" : "Failed ", i);
 
 	ret = XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_GPU, 0,
 										 0, NV_CTRL_GPU_MAX_CORE_THRESHOLD, &i);
-	fprintf(stderr, "%sNV_CTRL_GPU_MAX_CORE_THRESHOLD = %d\n", ret ? "" : "Failed ", i);
+	fprintf( stderr, "%sNV_CTRL_GPU_MAX_CORE_THRESHOLD = %d\n", ret ? "" : "Failed ", i);
 
 	/* ------------------------------------------------------------------------------*/
 	ret = XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_GPU, 0,
 										 0, NV_CTRL_AMBIENT_TEMPERATURE, &i);
-	fprintf(stderr, "%sNV_CTRL_AMBIENT_TEMPERATURE = %d\n", ret ? "" : "Failed ", i);
+	fprintf( stderr, "%sNV_CTRL_AMBIENT_TEMPERATURE = %d\n", ret ? "" : "Failed ", i);
 
 }
 
 void check_fans(Display *dpy, int *pData, int len)
 {
 	int ret;
-/* NV-CONTROL version 1.20 and above have the nessesary bits */
+
 	ret = XNVCTRLQueryTargetBinaryData (dpy, NV_CTRL_TARGET_TYPE_GPU, 0, 0,
 									NV_CTRL_BINARY_DATA_COOLERS_USED_BY_GPU,
 									(unsigned char **)(&pData), &len);
 
-	fprintf(stderr, "%sNV_COOLER_COUNT = %d\n", ret ? "" : "Failed ", ret ? pData[0]:0 );
+	fprintf( stderr, "%sNV_COOLER_COUNT = %d\n", ret ? "" : "Failed ", ret ? pData[0]:0 );
 
 	read_fanspeed(dpy,pData,len);
 }
 int main(void)
 {
-	unsigned long start_time, get_time;
-	struct timeval tv;
 	Display *dpy;
 	int old_hz, new_hz, old_mode, new_mode, def_2d;
 	int i;
 	char *str;
 	int *pData = 0, len = 0;
 
-	fprintf(stderr, "Getting system time\n");
-	gettimeofday(&tv, NULL);
-	start_time = tv.tv_sec;
-	fprintf(stderr, "Done\n");
 	dpy = XOpenDisplay(NULL);
 
 	XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_GPU, 0,
 										 0,NV_CTRL_GPU_ADAPTIVE_CLOCK_STATE , &i);
 	if ( i != NV_CTRL_GPU_ADAPTIVE_CLOCK_STATE_ENABLED ) {
-		fprintf(stderr, "ERROR - Driver not in Adaptive state\n");
-		return 2;
+		fprintf( stderr, "The driver is not operating in Adaptive clock state. Exiting\n");
+		return(1);
 	}
 
 	XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_GPU, 0,
 										 0,NV_CTRL_GPU_POWER_MIZER_MODE , &i);
 	if ( i != NV_CTRL_GPU_POWER_MIZER_MODE_ADAPTIVE ) {
-		fprintf(stderr, "ERROR - PowerMizer mode is not Adaptive.\n");
-		return 3;
-	}
-
-	fprintf(stderr, "Start of downclock monitoring\n");
+		fprintf( stderr, "The PowerMizer mode is not Adaptive. Exiting\n");
+		return(1);
+	}
+
+	fprintf( stderr, "Start of downclock monitoring\n");
 
 	XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
 										 0, NV_CTRL_NUM_GPU_ERRORS_RECOVERED, &i);
-	fprintf(stderr, "NV_CTRL_NUM_GPU_ERRORS_RECOVERED = %d\n",i);
+	fprintf( stderr, "NV_CTRL_NUM_GPU_ERRORS_RECOVERED = %d\n",i);
 
 	XNVCTRLQueryTargetStringAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
 										 0, NV_CTRL_STRING_PERFORMANCE_MODES, &str);
-	fprintf(stderr, "NV_CTRL_STRING_PERFORMANCE_MODES = %s\n", str);
+	fprintf( stderr, "NV_CTRL_STRING_PERFORMANCE_MODES = %s\n", str);
 
 	XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
 										0, NV_CTRL_GPU_CURRENT_PERFORMANCE_LEVEL, &old_mode);
-	fprintf(stderr, "NV_CTRL_GPU_CURRENT_PERFORMANCE_LEVEL = %d\n", old_mode);
+	fprintf( stderr, "NV_CTRL_GPU_CURRENT_PERFORMANCE_LEVEL = %d\n", old_mode);
 
 	XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
 										 0, NV_CTRL_GPU_DEFAULT_2D_CLOCK_FREQS, &def_2d);
-	fprintf(stderr, "NV_CTRL_GPU_DEFAULT_2D_CLOCK_FREQS = %x, Core = %d, Mem = %d\n",
+	fprintf( stderr, "NV_CTRL_GPU_DEFAULT_2D_CLOCK_FREQS = %x, Core = %d, Mem = %d\n",
 										 def_2d, ((def_2d & 0xFFFF0000) >> 16), (def_2d & 0xFFFF));
 
-/* XXX: compare with the default ones, but inside the program use these
-	XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
+/*	 XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
 										 0, NV_CTRL_GPU_2D_CLOCK_FREQS, &def_2d);
-	fprintf(stderr, "NV_CTRL_GPU_2D_CLOCK_FREQS = %x, Core = %d, Mem = %d\n",
+	fprintf( stderr, "NV_CTRL_GPU_2D_CLOCK_FREQS = %x, Core = %d, Mem = %d\n",
 										 def_2d, ((def_2d & 0xFFFF0000) >> 16), (def_2d & 0xFFFF));
 */
 	XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
 										 0, NV_CTRL_GPU_CURRENT_CLOCK_FREQS, &old_hz);
-	fprintf(stderr, "NV_CTRL_GPU_CURRENT_CLOCK_FREQS = %x, Core = %d, Mem = %d\n",
+	fprintf( stderr, "NV_CTRL_GPU_CURRENT_CLOCK_FREQS = %x, Core = %d, Mem = %d\n",
 										 old_hz, ((old_hz & 0xFFFF0000) >> 16), (old_hz & 0xFFFF));
 
+	check_bus_type(dpy);
 	check_fans(dpy, pData, len);
-	check_bus_type(dpy);
-	read_card_specific_registers();
-//	In case of integrated videocard, manualy edit the following line
-//	def_2d = 0;
 	do
 	{
-		gettimeofday(&tv, NULL);
-		get_time = tv.tv_sec;
-		if ((start_time + NOUVEAU_TIME_WAIT) < get_time ) {
-			fprintf(stderr, "ERROR - Timeout\n");
-			XCloseDisplay(dpy);
-			return 4;
-		}
-
+		
 		XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
 									 0, NV_CTRL_GPU_CURRENT_CLOCK_FREQS, &new_hz);
 		if (new_hz != old_hz) {
 			old_hz = new_hz;
-			fprintf(stderr, "Changed NV_CTRL_GPU_CURRENT_CLOCK_FREQS = %x, Core = %d, Mem = %d\n",
+			fprintf( stderr, "Changed NV_CTRL_GPU_CURRENT_CLOCK_FREQS = %x, Core = %d, Mem = %d\n",
 									 new_hz, ((new_hz & 0xFFFF0000) >> 16), (new_hz & 0xFFFF));
+			read_card_specific_registers();
+			read_fanspeed(dpy,pData,len);
 			read_bus_rate(dpy);
-			read_fanspeed(dpy,pData,len);
-			read_card_specific_registers();
 		}
 
 		XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
 									 0, NV_CTRL_GPU_CURRENT_PERFORMANCE_LEVEL, &new_mode);
 		if (new_mode != old_mode) {
 			old_mode = new_mode;
-			fprintf(stderr, "Changed NV_CTRL_GPU_CURRENT_PERFORMANCE_LEVEL = %d\n", new_mode);
+			fprintf( stderr, "Changed NV_CTRL_GPU_CURRENT_PERFORMANCE_LEVEL = %d\n", new_mode);
 		}
 
 	} while ( new_hz != def_2d );
 
-	fprintf(stderr, "Downclock monitoring finished\n");
+	fprintf( stderr, "Downclock monitoring finished\n");
 
 	check_temp(dpy);
 
 	XNVCTRLQueryTargetAttribute (dpy, NV_CTRL_TARGET_TYPE_X_SCREEN, 0,
 										 0, NV_CTRL_NUM_GPU_ERRORS_RECOVERED, &i);
 
-	fprintf(stderr, "Total NV_CTRL_NUM_GPU_ERRORS_RECOVERED = %d\n",i);
-	fprintf(stderr, "All done !!!\n");
+	fprintf( stderr, "Total NV_CTRL_NUM_GPU_ERRORS_RECOVERED = %d\n",i);
+	fprintf( stderr, "All done !!!\n");
+
 
 	XCloseDisplay(dpy);
 
+
+
 	return 0;
 }