Minor clean up
Fix termination condition