Fixed some bugs, regarding previous commit