Made a single graphics replay initialization loop.

Combined checking for extensions and finding the handles of programs to cache into a single loop upon loading. Also cached programs that were linked only once and not deleted in the trace. Fixes #414.