Updated for XE16, and added unit tests.