Revert "try to make code more thread save"

This reverts commit 2f3a24d9065a5f7c86f0e0871f2ec45187561b20.
Revert "try to make data structures thread save by using a mutex"

This reverts commit 88d64d65ab05acf95912f022a693f788e81b9be2.
use threadsave libc. Prepare code for locks. Separate tree and tree elements. Use c99 standard.