Reorganize function order
Introduce a software TLS implementation

This is highly unoptimized but works.