Adding looping
Cleaned up code