First working version of the gridMomenta function.