Fixed crash on close app.
Some cleanup.