Fixed some functions and some bugs.