Fix building as a static extension
Some zts fixes