Pass modes as parameters instead of calculating them inplace.