Added proper shutdown