Cleanup resources on exit

Linked to #3