Add more comments, minor bug fixes