Moved up 24 lines to beginning of this code block.