Moving code around, cleanups