Add better endgame code