add comments, bugs fixed