Moved some code around for continuity