Refactoring

Use auto and for loops more often and remove compiler warnings