Bugs fix and improvements

Bugs fix and improvements