Added functions

General fixes everywhere, too.