Fixed some bugs and changes due to merge