add comments and fixes some problems