Rewrote the lib with a more modular style.