having some weird errors raised with a for loop