improve merge code
reference top-level classes instead of modules