Patch 13

some improvements of code