I think I might have used too many layers of for() and multiplication of different variables.

This is getting tricky to debug.