Refactored Venkat's code in http://agiledeveloper.com/downloads.html