Format
Remove cross-call state
form_btree_data separately
Clean up, release hw lock last
Free scankey memory
Move most logic to worker function