Moved some functions around
Has a problem but I'm going home now