Fixed incorrect loop condition - still not working