Merged some for loops to reuse more code