Cleaned up comments, reorganized code slightly.