working implementation with some tests
allocation cleanup and exception tests