Don't set this until after all the error checking. Move the ts init down there too.