Refactor XM loader

Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>