Add comments, fix ref bugs