Fr rewrite

made this thing more modular.