Improved init and cleanup