loops working as planned but need refactoring