Moved some code around to prevent potential errors