Cleaned up main().
Added another function for error handling.
Added OpenGL context, i don't know why.