Fix for some bugs