Made lines 346-369 more readable and added comment.