comments added, explaining what each line does