Improve device parsing

Allocate peer arrays when parsing devices
Add close_endpoints() for cleanup