Moved code around a bit.