refact code, make scan and merge as interface