Move stuff around and fix references