Improve HGM import script for sort/swap on A and B entries