Added comments explaining what the code does