Correct grammar and added more comments so it is more understandable