Move some stuff down to prevent concurrency issues, see #315