fixed some bugs

see commit description bellow