Fixed up bugs and added comments.