added comments, made the code more readable