Refactor gl handler