fix the infinite loop and round up