diff --git a/.GLHUI.cabal.swp b/.GLHUI.cabal.swp
deleted file mode 100644
Binary files a/.GLHUI.cabal.swp and /dev/null differ
diff --git a/GLHUI.cabal b/GLHUI.cabal
--- a/GLHUI.cabal
+++ b/GLHUI.cabal
@@ -1,11 +1,10 @@
 name: GLHUI
-version: 1.0.0
+version: 1.1.0
 license: BSD3
 license-file: LICENSE
 author: Hugo Gomes <mr.hugo.gomes@gmail.com>
 maintainer: Hugo Gomes <mr.hugo.gomes@gmail.com>
 copyright: Hugo Gomes
-homepage: http://www.hackological.com/projects/GLHUI
 category: Graphics
 synopsis: Open OpenGL context windows in X11 with libX11
 description:
@@ -36,11 +35,13 @@
    >           Window.loop myLoop -- stops when the ESC key is pressed
    >           Window.kill -- removes the window when the loop stops
    .
-   Special thanks to Tiago Farto (aka xernobyl) for coding the C version of
-   these functions
+   Special thanks to Tiago Farto (aka xernobyl) for coding the initial C version
+   that was used as a base for these functions
 build-type: Simple
 cabal-version: >=1.6
 extra-source-files:
+   include/HsGLWindow.h
+   c/HsGLWindow.c
    README
 
 library
diff --git a/c/HsGLWindow.c b/c/HsGLWindow.c
--- a/c/HsGLWindow.c
+++ b/c/HsGLWindow.c
@@ -17,6 +17,12 @@
     unsigned long	status;
 } Hints;
 
+// OpenGL 3 specific functions:
+// GLXContext glXCreateContextAttribsARB (Display *, GLXFBConfig, GLXContext, Bool direct, const int *);
+typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
+typedef Bool (*glXMakeContextCurrentARBProc)(Display*, GLXDrawable, GLXDrawable, GLXContext);
+static glXCreateContextAttribsARBProc createContext = 0;
+static glXMakeContextCurrentARBProc makeContextCurrent = 0;
 
 void WindowSetFullscreen(int f)
 {
@@ -27,8 +33,7 @@
 
 	hints.flags = 2;
 
-	if(f)
-	{	
+	if(f) {	
 		hints.decorations = False;
 	
 		changes.x = 0;
@@ -38,9 +43,7 @@
 		changes.stack_mode = Above;
 
 		fullscreen = 1;
-	}
-	else
-	{
+	} else {
 		hints.decorations = True;
 
 		changes.x = scrwidth/4;
@@ -60,34 +63,86 @@
 	//XMapRaised(display, window);
 }
 
+// GL Attributes
+static const int basicAttribs[] = { GLX_RGBA
+                                  , GLX_DEPTH_SIZE, 24
+                                  , GLX_DOUBLEBUFFER
+                                  , None 
+                                  };
+static const int gl3Attribs[] = { GLX_RENDER_TYPE, GLX_RGBA_BIT
+                                , GLX_X_RENDERABLE, True
+                                , GLX_DOUBLEBUFFER, 1
+                                , GLX_RED_SIZE, 8
+                                , GLX_GREEN_SIZE, 8
+                                , GLX_BLUE_SIZE, 8
+                                , None
+                                };
 
-int WindowInit(unsigned int const major, unsigned int const minor)
-{
-	static const int glattr[] =
-	{
-		GLX_RENDER_TYPE, GLX_RGBA_BIT,
-		GLX_X_RENDERABLE, 1,
-		GLX_DOUBLEBUFFER, 1,
-		GLX_RED_SIZE, 8,
-		GLX_GREEN_SIZE, 8,
-		GLX_BLUE_SIZE, 8,
-		0
-	};
 
-	int gl3attr[] =
-	{
-		GLX_CONTEXT_MAJOR_VERSION_ARB, major,
-		GLX_CONTEXT_MINOR_VERSION_ARB, minor,
-		GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
-		0
-	};
+typedef struct {
+    unsigned int major, minor, GLSLMajor, GLSLMinor;
+} support;
 
-	if(!(display = XOpenDisplay(0)))
-	{
-		puts("Could not open display.\n");
+// This function creates a throw away context that is only used to query
+// for support of specific features, like what version of opengl is supported
+
+// the minimal context needs a display and a visual;
+support _initSupport(Display *dpy) {
+    XVisualInfo *vi = glXChooseVisual(dpy, 0, (int*)basicAttribs);
+    if(vi == NULL) { 
+        fprintf(stderr, "Unable to create the throw away context");
+        fprintf(stderr, "No appropriate visual found");
+        // TODO: return invalid support
+    }
+
+    Window                  root;
+    Colormap                cmap;
+    XSetWindowAttributes    swa;
+    Window                  win;
+    GLXContext              glc;
+
+    root = DefaultRootWindow(dpy);
+    cmap = XCreateColormap(dpy, root, vi->visual, AllocNone);
+    swa.colormap = cmap;
+    win = XCreateWindow(dpy, root, 0, 0, 16, 16, 0, vi->depth, InputOutput, vi->visual, CWColormap, &swa);
+
+    glc = glXCreateContext(dpy, vi, NULL, GL_TRUE);
+    glXMakeCurrent(dpy, win, glc);
+    char const * version = glGetString(GL_VERSION);
+    unsigned int major = version[0] - '0';
+    unsigned int minor = version[2] - '0';
+    unsigned int glslMajor = 0;
+    unsigned int glslMinor = 0;
+    if(major >= 2) {
+        char const * glsl = glGetString(GL_SHADING_LANGUAGE_VERSION);
+        glslMajor = glsl[0] - '0';
+        glslMinor = glsl[2] - '0';
+    }
+	// printf("TMP CONTEXT: OpenGL:\n\tvendor %s\n\trenderer %s\n\tversion %s\n\tshader language %s\n", glGetString(GL_VENDOR), glGetString(GL_RENDERER), glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION));
+    /* get the required extensions */
+    createContext = (glXCreateContextAttribsARBProc)glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB");
+    makeContextCurrent = (glXMakeContextCurrentARBProc)glXGetProcAddressARB( (const GLubyte *) "glXMakeContextCurrent");
+    if ( !(createContext && makeContextCurrent) && major > 2){
+        fprintf(stderr, "missing support for GLX_ARB_create_context\n");
+        // TODO: return invalid support
+    }
+
+	glXDestroyContext(dpy, glc);
+    XDestroyWindow(dpy, win);
+
+    support s = { major, minor, glslMajor, glslMinor };
+    return s;
+}
+
+int WindowInit(unsigned int const major, unsigned int const minor)
+{
+    display = XOpenDisplay(NULL);
+	if(display == NULL) {
+		puts("Cannot connect to the X server.\n");
 		return -1;
 	}
-
+    support s = _initSupport(display); // check what the system supports
+    // printf("Opengl Major: %d, Opengl Minor: %d, GLSL Major: %d, GLSL Minor %d\n", s.openGLMajor, s.openGLMinor, s.GLSLMajor, s.GLSLMinor);
 	int nscreen = DefaultScreen(display);
 	scrwidth = XDisplayWidth(display, nscreen);
 	scrheight = XDisplayHeight(display, nscreen);
@@ -95,22 +150,36 @@
 	width = scrwidth / 2;
 	height = scrheight / 2;
 
-	static XVisualInfo *visual;
-	if(!(visual = glXChooseVisual(display, nscreen, (int*)glattr)))
-	{
+	int const * glattr;
+    if(s.major > 2) {
+        glattr = gl3Attribs;
+    } else {
+        glattr = basicAttribs;
+    }
+	XVisualInfo *visual = glXChooseVisual(display, nscreen, (int*)glattr);
+	if(visual == NULL) {
 		puts("Could not find a visual.\n");
 		return -2;
 	}
 	
-	int elemc;
-	GLXFBConfig *fbcfg = glXChooseFBConfig(display, nscreen, glattr, &elemc);
-	if(!fbcfg)
-	{
-		puts("Could not find FB config.\n");
-		return -3;
-	}
-
-	context = glXCreateContextAttribsARB(display, fbcfg[0], 0, 1, gl3attr);
+    if(major >= 3) {
+        int elemc;
+        GLXFBConfig *fbcfg = glXChooseFBConfig(display, nscreen, glattr, &elemc);
+        if(fbcfg == NULL) {
+            puts("Could not find FB config.\n");
+            return -3;
+        }
+        int gl3attr[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, major
+                        , GLX_CONTEXT_MINOR_VERSION_ARB, minor
+                        , GLX_CONTEXT_FLAGS_ARB
+                        , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
+                        , None
+                        };
+        context = createContext(display, fbcfg[0], 0, 1, gl3attr);
+        XFree(fbcfg);
+    } else {
+        context = glXCreateContext(display, visual, NULL, GL_TRUE);
+    }
 
 	Window root = RootWindow(display, visual->screen);
 
@@ -128,7 +197,6 @@
 	glXMakeCurrent(display, window, context);
 	glViewport(0, 0, width, height);
 
-	XFree(fbcfg);
 	XFree(visual);
 
 	printf("OpenGL:\n\tvendor %s\n\trenderer %s\n\tversion %s\n\tshader language %s\n", glGetString(GL_VENDOR), glGetString(GL_RENDERER), glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION));
@@ -187,12 +255,11 @@
 }
 
 
-void WindowKill(const char *str)
+void WindowKill()
 {
-	puts(str);
-
-	if(context)
-	{
+    puts("Bye.");
+	if(context) {
+        XDestroyWindow(display, window);
 		glXMakeCurrent(display, 0, 0);
 		glXDestroyContext(display, context);
 		context = 0;
@@ -209,4 +276,3 @@
 unsigned WindowHeight(){ return height; }
 unsigned WindowScrWidth(){ return scrwidth; }
 unsigned WindowScrHeight(){ return scrheight; }
-
