general code cleaning, added some comments