Fixed various issues.

Byte tests left invalid upper bytes that were later reused in some circumstances.
The active code page could be deleted and later used after module destruction.
The critical section memory was being leaked.