Moved code around to logical spot