Hi, Thanks to Barry Rawlinson and Sundar Dorai-Raj the problem was solved. The problem was that I was doing integer division when I should have been doing float division followed by ceil or floor. Sorry about that and many thanks to those who took the time to look at this. Best, Guy