Fixed a few minor bugs.
Rename a few functions.