Missed a few lines in there, and set some functions in the wrong place.