Moving code around, test fixes