Changed merge and added helper functions.