ugly version with RefCells and managed boxes
slightly cleaner