Fr rewrite

made this thing more modular. As step 1 of making it better. Want this merged on master before making next changes.