Fixed bugs in some of the functions.