Bug fix

- Loop bugs fixed