Fixed some bugs and updated some functions