ex-48 - (jebene/kmeng): refactored merge and expand to fix segfualt bug