Refactored. Fixes glew issues for macos.