combine horizontal and vertical merge funtions and clean up useless code