Cleanup and const correctness
PUt data structs into a namespace
Cleanup: const correctness
Rework occurence handling, fix memory management