Some performance optimizations, fixed OpenGL stack overflow