simple loops working, nested loops don't derive