some improvements

Some comments added and some lines refactored. 

tested with current unittests