chore (move receive to a loop)

also add close