Move some code around