added some comments and some tweaks