Moved init code into constructors and destruction into destructors. I have no idea if this works.