added comments, added debug option