Restructured
Rewrote some parts to eliminate compilation warnings