Move some code around to clean it up more.