Code cleanup + lots of comments.