Fixed some bugs and updated some functions

Moved stuff around too.