grab allocations correctly
fix bugs
add a test