refactoring bug fixing and inputmerge2