Code thoroughly commented.