merges two function