changed function to sapply
added combine.elements function
updated math of combine.elements
fixed merge