Fixed some bugs from last merge