Fix infinite loop, add test output