Significantly modularized, improved code
Significantly modularized, improved code
Updated version