Fixed some bugs, updated some functions.