Move some more code around to make it shorter