Moving functions around, other fixups