Added proper shutdown (using hack).