refactor 001-010

remove variables used only for loops
and make variable names clearer (e.g. don't use n and num in the same function!!)