Adjust to API changes. Also move some stuff around