Fixed some bugs and formatting errors