Fix length of for loops to match buffer size (fix #95)