Rewrote several libraries to have better memory management
Small optimalizations