changed implementation of harmonize() from multiple if cases to iterative; didn't use recursive implementation because it's costly in Java