trying to avoid some for loops