Added some functions and made small modifications to many others.