Made suggested changes and added some more thorough comments.