Refactor a bit

Optimize the end, result reporting, part of glad.py a little bit.