added some comments and general fixes