Organized a bit, made some functions local that don't need to be exposed.