Memory management cleanup
Some major refactoring, started on POST