Enhanced Code: added comments and some more analysis