Some code fixes and added coments