Refactor for xbee