Updated with better explanation of how the code functions