Loop instead of duplicate code