cleanups and fmrmr function