Almost completed implementation of RGE algorithm.