Updated with comments and explanations