mostly works, need refinement