Restructured, commented & cleaned up.