Fixed infinite loop, prints correct output
merge