added nxd function and tidied output