Fixed code, added comments including example execution demo.