refactor of ffx code