I agree this piece of code is not very elegant, but i fear your proposed solution would mean to iterate 4 times the indices array instead of once.